home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: phcoms4.seri.philips.nl!misf1!Pvestjen
- From: Pvestjen@ms.philips.nl (Patrick Vestjens)
- Subject: Re: confusion between putchar and printf
- Message-ID: <1996Mar13.075322.12898@ms.philips.nl>
- Sender: news@ms.philips.nl
- Organization: Philips Medical Systems, Best
- X-Newsreader: TIN [version 1.2 PL2]
- References: <4i1v2n$30o@news.azstarnet.com>
- Date: Wed, 13 Mar 1996 07:53:22 GMT
-
- Howard Salmon (captarm@azstarnet.com) wrote:
- : K & R (section 1.5) states that "putchar(c) prints the contents of the
- : integer variable c as a character, usually on the screen".
-
- : Here's a small program that I wrote testing putchar. Why doesn't it
- : compile?
-
- : #include <stdio.h>
- : # define A "hello world!"
-
- : main()
- : {
- : int c;
- : c = A;
- : putchar(A);
- : }
-
- : Thanks,
- : Howard Salmon (captarm@azstarnet.com)
-
- After macro-expansion, your main looks like:
-
- main()
- {
- int c;
- c = "hello world!";
- putchar("hello world!");
- }
-
- In other words, you're assigning a string constant to an integer
- variable and, in the second case, you're passing a string constant as to
- a function that expects an integer parameter. I'm not surprised that the
- compiler doesn't accept this code.
-
- Don't know what you exactly want to do, but perhaps you should try
- printf, for example like this:
-
- printf("%s", A);
-
- which is expanded to:
-
- printf("%s", "hello world!");
-
- Success, Patrick.
-
-
-